<!--成绩参数设置-->
<template>
    <div class="wrapper-container" style="width:100%">
    <div class="table-container" style="margin:0">
      <!-- <el-button type="primary" @click="elequeryall">buttonCont</el-button>-->
      <el-table
        :data="tableData"
        style="width: 100%"
        class="xpaas-table-class"
        row-class-name="xpaas-row-class"
        cell-class-name="xpaas-cell-class"
        header-row-class-name="xpaas-header-row-class"
        header-cell-class-name="xpaas-header-cell-class"
      >
        <el-table-column
          width="300"
          prop="paramname"
          label="参数名称"
          align="center"
        >
        </el-table-column>
        <el-table-column
          width="600"
          prop="paramdesc"
          label="参数说明"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="staratvalue" label="是（默认值）" align="center">
        </el-table-column>
        <el-table-column prop="currentlyvalue" label="否（当前值）" align="center"></el-table-column>
        <el-table-column label="修改" align="center">
          <template slot-scope="scope">
            <SelectItem
              v-if="scope.row.fixType==='select'"
              :name="''"
              :value="scope.row.fixValue"
              @change="
                (e) => {
                  scope.row.fixValue = e;
                }
              "
              :xqList="scope.row.fixList"
            ></SelectItem>

            <InputItem
              v-else
              :name="''"
              :value="scope.row.fixValue"
              @input="
                (e) => {
                  scope.row.fixValue = e;
                }
              "
            ></InputItem>
          </template>
        </el-table-column>
        <el-table-column prop="back" label="恢复" align="center">
          <template slot-scope="scope">
            <div style="margin: 0 auto;font-size: 14px;font-weight: 600;
    width:120px;
    border-radius: 6px;
    color: #f3b815;
    background:#fff6ef;
    border: 1px solid #f3b815;cursor: pointer;" @click="RecoverByname(scope.$index)">恢复为初始值</div>
            <!-- <ButtonItem
              style="margin: 0 auto;color:#f3b815"
              :name="'恢复为初始值'"
              :link="''"
              :icon="''"
              @click="RecoverByname(scope.$index)"
              :buttonColor="'yellow'"
            ></ButtonItem> -->
          </template>
        </el-table-column>
      </el-table>
    </div>

    <div
      class="search-container"
      style="display: flex; justify-content: center !important"
    >
    <div class="saveBtn" @click="updateele()">保 存</div>
      <!-- <ButtonItem
        :name="'保 存'"
        :link="''"
        :icon="''"
        @click="updateele()"
      ></ButtonItem> -->
    </div>
  </div>
</template>

<script>
import SelectItem from "../../../components/SelectItem.vue";
import InputItem from "../../../components/InputItem.vue";
import ButtonItem from "../../../components/ButtonItem.vue";
import {elequeryall, updateele} from "@/api/admin1/check";

export default {
  components: {
    SelectItem,
    InputItem,
    ButtonItem,
  },
  data() {
    return {
      tableData: []
    };
  },

  mounted() {
    this.elequeryall()
  },
  methods: {
    //  成绩参数设置查询
    elequeryall() {
      return new Promise(() => {
        elequeryall().then(res => {
          if (res.status === 200) {
            let data = res.data
            for (const dataKey in data) {
              data[dataKey].fixValue =  data[dataKey].currentlyvalue
              data[dataKey].fixList = [
                {
                  value: "是",
                  label: "是",
                },
                {
                  value: "否",
                  label: "否",
                },
              ]
            }
            this.tableData = res.data
          }
        })
      })
    },
    RecoverByname(index) {
      // this.tableData[index].currentlyvalue = this.tableData[index].staratvalue
      this.tableData[index].fixValue = this.tableData[index].staratvalue;
    },
    //  成绩参数设置保存
    updateele() {
      let data = this.tableData
      for (const dataKey in data) {
        if(data[dataKey].fixValue){
          data[dataKey].currentlyvalue = data[dataKey].fixValue
        }
      }
      return new Promise(() => {
        updateele(data).then(() => {
          this.elequeryall()
          this.$message({
            message: '成绩参数保存成功！',
            type: 'success'
          })
        })
      })
    },
    //  成绩参数恢复初始值
  },
};
</script>
<style lang="less" scoped>
.search-container {
  justify-content: flex-start !important;
  .saveBtn {
    cursor: pointer;
    font-size: 18px;
    padding: 9px 22px;
    border-radius: 6px;
    color: #f3b815;
    border: 1px solid #f3b815;
    background: #fff6ef;
  }
}

.search-button {
  cursor: pointer;
  box-sizing: border-box;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 27px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;

  > span {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }

  > img {
    width: 19px;
    height: 19px;
    margin-right: 4px;
  }
}

.table-container {
  margin-top: 15px;

  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
}
</style>

<style lang="less" scoped>
@import "../../../styles/special.less";

.table-container::v-deep .el-table__header th {
  border-color: #c7d7eb !important;
  padding-left: 10px;
}

.filter-button::v-deep .el-radio-button .el-radio-button__inner {
  border-radius: 6px !important;
  border: 1px solid #02c86c;
  color: #02c86c;
  background-color: #dfffef;
}

.filter-button::v-deep
.el-radio-button__orig-radio:checked
+ .el-radio-button__inner {
  border: 1px solid #02c86c;
  color: white;
  background-color: #02c86c;
}

.wrapper-container {
  width: 1711px;
  margin: 0 auto;
}

.table-container {
  margin-top: 15px;

  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    border-radius: 9px;
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.save-button {
  width: 87px;
  height: 36px;
  line-height: 36px;
  background: #fff6ef;
  border: 1px solid #f3b815;
  border-radius: 6px;
  font-size: 18px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #f3b815;
  text-align: center;
  margin: 82px auto;
}

.zuoyou {
  width: 200px;
  display: flex;
  flex-direction: row;
  justify-content: space-between;
}

@fontFamily:"Microsoft YaHei";
.xpaas-table-class {
  border: 1px solid #004ca7;
  border-radius: 9px;
  > ::v-deep div.el-table__header-wrapper {
    > table.el-table__header {
      > thead {
        > tr.xpaas-header-row-class {
          padding: 0;
          height: 76px;
          background-color: #edf2f9;
          font-size: 16px;
          font-family: Microsoft YaHei;
          font-weight: bold;
          line-height: 20px;
          color: #004ca7;
          > th.xpaas-header-cell-class {
            font-weight: bold;
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
  > ::v-deep div.el-table__body-wrapper {
    > table.el-table__body {
      > tbody {
        > tr.xpaas-row-class {
          > td.xpaas-header-cell-class {
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            background-color: #edf2f9;
            > div.cell {
              font-size: 16px;
              font-weight: bold;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
          > td.xpaas-cell-class {
            height: 76px;
            
            border-right: 1px solid #c7d7eb;
            border-left: 0;
            border-bottom: 1px solid #c7d7eb;
            > div.cell {
              font-weight: normal;
              font-family: @fontFamily;
              color: #004ca7;
            }
          }
        }
      }
    }
  }
}
</style>
